home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / clean / sun3.lha / Sun3 / pardemos / pnfib.icl < prev    next >
Text File  |  1992-08-07  |  1KB  |  45 lines

  1. MODULE pnfib;
  2.  
  3. <<
  4. Parallel Nfib.
  5.  
  6. Parallel version of the Nfib function.
  7. When the argument of the Nfib function is greater than a certain threshold
  8. the function will be evaluated in parallel, otherwise the "normal"
  9. (sequential) evaluation will proceed.
  10. >>
  11.  
  12. IMPORT deltaI;
  13.  
  14.  
  15. MACRO
  16.  
  17.     Threshold   -> 12;  == The threshold for parallel evaluation of Nfib.
  18.     StartValue  -> 18;  == The initial value for the call of Nfib.
  19.  
  20.  
  21. RULE
  22.  
  23. <<  Parallel Nfib. When n is greater than or equal to the threshold
  24.     a parallel process for the evaluation of Nfib n-1 ({P} left) will
  25.     be created. Nfib n-2 will be computed by the original process.
  26.     When n is smaller than the threshold the Nfib function will be 
  27.     calculated sequentially.
  28.     The strictness analyzer doesn't analyze functions with parallel annotations
  29.     because that could lead to unexpected (and unwanted) results. For efficency
  30.     reasons this function has been user-annotated.
  31. >>
  32.  
  33. ::  PNfib !INT  -> INT;
  34.     PNfib n     -> 1                    , IF < n 2
  35.                 -> ++ (+ left right)    , IF < n Threshold
  36.                 -> ++ (+ {P} left right),
  37.                    left:  PNfib (-- n),
  38.                    right: PNfib (- n 2);
  39.  
  40.  
  41. ==  The Start rule: call PNfib with its startvalue.
  42.  
  43. ::  Start -> INT;
  44.     Start -> PNfib StartValue;
  45.